package com.AAL.DAO;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.classic.Session;

import com.AAL.DAO.Interface.IStatusOfContractDAO;
import com.AAL.Model.StatusOfContract;
import com.AAL.Utils.HibernateUtil;

public class StatusOfContractDAO implements IStatusOfContractDAO {

	@Override
	public StatusOfContract getStatusOfContract(int statusID) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		StatusOfContract statusOfContract = (StatusOfContract) session.load(
				StatusOfContract.class, statusID);
		return statusOfContract;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<StatusOfContract> getAllStatusOfContracts() {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		List<StatusOfContract> lstStatusOfContracts = null;
		try {
			lstStatusOfContracts = (List<StatusOfContract>) session
					.createQuery("from StatusOfContract").list();
		} catch (HibernateException e) {
			e.printStackTrace();
			session.getTransaction().rollback();
		}
		session.getTransaction().commit();
		return lstStatusOfContracts;
	}

}
